<template>
  <el-menu
    active-text-color="rgb(64,158,255)"
    background-color="#304256"
    class="el-menu-vertical-demo"
    text-color="#fff"
    :collapse="props.isCollapse"
    router
    unique-opened
    :default-active="dafUrl"
  >
    <el-menu-item index="/index">
      <i class="iconfont homepage"></i>
      <span>首页</span>
    </el-menu-item>
    <el-sub-menu
      :index="'/' + item1.name"
      v-for="item1 in menus"
      :key="item1.id"
    >
      <template #title>
        <i class="iconfont" :class="item1.icon"></i>
        <span>{{ item1.title }}</span>
      </template>
      <template v-for="item2 in item1.children" :key="item2.id">
        <el-menu-item
          :index="'/' + item1.name + '/' + item2.name"
          v-if="item2.hidden === 0"
        >
          <i class="iconfont" :class="item2.icon"></i>
          {{ item2.title }}</el-menu-item
        >
      </template>
    </el-sub-menu>
  </el-menu>
</template>

<script setup lang="ts">
import { useUserStore } from "@/store/User";
import { useRoute } from "vue-router";
import { ref, watch } from "vue";
const props = defineProps(["isCollapse"]);
const userStore = useUserStore();
const route = useRoute();
const menus = userStore.routes;
const dafUrl = ref("/index");
watch(
  () => route.path,
  () => {
    dafUrl.value = route.path;
  },
  {
    immediate: true,
  }
);
</script>

<style scoped></style>
